package com.ruoyi.mq.config;

import com.ruoyi.mq.service.MessageProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class StrategyConfig {

    @Bean
    public Map<String, MessageProcessor> messageProcessors(ApplicationContext applicationContext) {
        Map<String, MessageProcessor> processors = new HashMap<>();
        String[] beanNames = applicationContext.getBeanNamesForType(MessageProcessor.class);
        for (String beanName : beanNames) {
            MessageProcessor processor = applicationContext.getBean(beanName, MessageProcessor.class);
            processors.put(beanName, processor);
        }
        return processors;
    }
}
